
RequestDelegate handler = context => context.Response.WriteAsync("Hello, World!");


var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

var app = builder.Build();

// Configure the HTTP request pipeline.
IApplicationBuilder appBuilder = app;
appBuilder
    .Use(middleware: HelloMiddleware)
    .Use(middleware: WorldMiddleware);

//app.Run(handler: handler);
//app.Run(handler: HandleAsync);
//app.Run(context =>
//{
//    return context.Response.WriteAsync("Hello, World!");
//});
app.Run();


static Task HandleAsync(HttpContext httpContext) => httpContext.Response.WriteAsync("Hello, World!");


static RequestDelegate HelloMiddleware(RequestDelegate next)
    => async httpContext => {
        await httpContext.Response.WriteAsync("Hello, ");
        await next(httpContext);
    };

static RequestDelegate WorldMiddleware(RequestDelegate next) => httpContext => httpContext.Response.WriteAsync("World!");

static async Task HelloMiddleware1(HttpContext httpContext, RequestDelegate next)
{
    await httpContext.Response.WriteAsync("Hello, ");
    await next(httpContext);
};

static Task WorldMiddleware1(HttpContext httpContext, RequestDelegate next) => httpContext.Response.WriteAsync("World!");

static async Task HelloMiddleware2(HttpContext httpContext, Func<Task> next)
{
    await httpContext.Response.WriteAsync("Hello, ");
    await next();
};

static Task WorldMiddleware2(HttpContext httpContext, Func<Task> next) => httpContext.Response.WriteAsync("World!");